package com.mo.axion.handler.utils;

import com.mo.axion.common.domain.TaskInfo;
import com.mo.axion.common.enums.ChannelType;
import com.mo.axion.common.enums.EnumUtil;
import com.mo.axion.common.enums.MessageType;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Mo
 * @createTime 2024/2/17 18:12
 * @description 消费者组映射工具类, groupId标志着每个消费者组
 */
public class GroupIdMappingUtils {
    /**
     * 获取所有类型的groupId
     * @return
     */
    public static List<String> getAllGroupIdList() {
        List<String> groupIdList = new ArrayList<>();
        for (ChannelType channelType : ChannelType.values()) {
            for (MessageType messageType : MessageType.values()) {
                groupIdList.add(channelType.getCodeEn() + "." + messageType.getCodeEn());
            }
        }
        return groupIdList;
    }

    /**
     * 根据TaskInfo获取当前消息的groupId
     * @param taskInfo 消息
     * @return 当前消息的groupId
     */
    public static String getGroupIdByTaskInfo(TaskInfo taskInfo) {
        String channelCodeEn = EnumUtil.getEnumByCode(taskInfo.getSendChannel(), ChannelType.class).getCodeEn();
        String msgCodeEn = EnumUtil.getEnumByCode(taskInfo.getMsgType(), MessageType.class).getCodeEn();
        return channelCodeEn + "." + msgCodeEn;
    }
}
